<?php
	global $_W,$_GPC;
	if($_W['role']){
		if($_W['isajax']){
			$stropenid = $_GPC['openid'];
			if($stropenid){
				$arr = explode('||', $stropenid);
				$openid = json_encode($arr);
			}else{
				$openid = '';
			}
			$strphone = $_GPC['admin_phone'];
			if($strphone){
				$arrs = explode('||',$strphone);
				$admin_phone = json_encode($arrs);
			}else{
				$admin_phone = '';
			}
			$data = array(
				'uniacid'=>$_W['uniacid'],
				'companyname'=>$_GPC['companyname'],
				'starthours'=>$_GPC['starthours'],
				'endhours'=>$_GPC['endhours'],
				'phone'=>$_GPC['phone'],
				'videourl'=>$_GPC['video'],
				'copyright'=>$_GPC['copyright'],
				'address'=>$_GPC['address'],
				'lat'=>$_GPC['lat'],
				'lng'=>$_GPC['lng'],
				'Blat'=>$_GPC['Blat'],
				'Blng'=>$_GPC['Blng'],
				'logo'=>$_GPC['logo'],
				'pics'=>$_GPC['pics'],
				'msg_templateid'=>$_GPC['msg_templateid'],
				'openid'=>$openid,
				'msg_roof'=>$_GPC['msg_roof'],
				'admin_phone'=>$admin_phone,
				'is_pay'=>$_GPC['is_pay']
			);
			$exist = pdo_get('mii_ang_info',array('uniacid'=>$_W['uniacid']),array('id'));
			if(empty($exist)){
				$ins = pdo_insert('mii_ang_info',$data);
				if($ins){
					$code = array('status'=>'1','msg'=>'设置成功！');
					echo json_encode($code);
					upfunc();
					exit();
				}else{
					$code = array('status'=>'2','msg'=>'设置失败！');
					echo json_encode($code);
					exit();					
				}
			}else{
				$up = pdo_update('mii_ang_info',$data,array('uniacid'=>$_W['uniacid']));
				if($up){
					$code = array('status'=>'1','msg'=>'设置成功！');
					echo json_encode($code);
					exit();
				}else{
					$code = array('status'=>'2','msg'=>'设置失败！');
					echo json_encode($code);
					exit();					
				}
			}
		}
	}else{
		$code = array('status'=>'2','msg'=>'没有操作的权限');
		echo json_encode($code);
		exit();
	}

	function upfunc(){
		global $_W;
		$webinfo = pdo_get('mii_ang_info',array('uniacid'=>$_W['uniacid']));
		$ad = pdo_fetchall("SELECT imgurl,linkgoodsid FROM ".tablename('mii_ang_ad')."WHERE uniacid=:uniacid AND term >= :term ORDER BY orderid DESC",array(':uniacid'=>$_W['uniacid'],':term'=>$_W['timestamp']));
		$men = pdo_fetchall(" SELECT id,categoryname,bg_color FROM".tablename('mii_ang_class')." WHERE uniacid=:uniacid AND ishide=:ishide ORDER BY category_order DESC LIMIT 4",array(':uniacid'=>$_W['uniacid'],':ishide'=>'1'));
		$hot = pdo_fetchall("SELECT id,goodsname,titlepic,price FROM".tablename('mii_ang_goods')." WHERE uniacid=:uniacid AND ishot=:ishot",array(':uniacid'=>$_W['uniacid'],':ishot'=>'1'));
		if($webinfo['adinfo']){
			$adinfo = json_decode($webinfo['adinfo'],true);
		}else{
			$adinfo = array('empty'=>'yes');
		}
		$data = array('webinfo'=>$webinfo,'ad'=>$ad,'men'=>$men,'hot'=>$hot,'adinfo'=>$adinfo);
		$siteinfo = json_encode($data);
		$isdata = pdo_get('mii_ang_siteinfo',array('uniacid'=>$_W['uniacid']),array('id'));
		if(!empty($isdata)){
			$up = pdo_update('mii_ang_siteinfo',array('siteinfo'=>$siteinfo),array('uniacid'=>$_W['uniacid']));
		}else{
			$ins = pdo_insert('mii_ang_siteinfo',array('uniacid'=>$_W['uniacid'],'siteinfo'=>$siteinfo));
		}
	}
?>